<?php

namespace App\Entity\Wuliu;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use App\Repository\Wuliu\WuliuGoodsTypeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass=WuliuGoodsTypeRepository::class)
 */
class WuliuGoodsType
{
    /**
     * @Common(cnName="#",editType="text",listType="text")
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"order"})
     */
    private $id;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"order"})
     */
    private $name;

    /**
     * @Common(cnName="说明",editType="text",listType="text",width="")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"order"})
     */
    private $intro;

    /**
     * @Common(cnName="排序",editType="text",listType="text")
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"order"})
     */
    private $sort;

    /**
     * @ORM\OneToMany(targetEntity=WuliuOrder::class, mappedBy="goods")
     */
    private $wuliuOrders;

    public function __construct()
    {
        $this->wuliuOrders = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getIntro(): ?string
    {
        return $this->intro;
    }

    public function setIntro(?string $intro): self
    {
        $this->intro = $intro;

        return $this;
    }

    public function getSort(): ?int
    {
        return $this->sort;
    }

    public function setSort(?int $sort): self
    {
        $this->sort = $sort;

        return $this;
    }

    /**
     * @return Collection|WuliuOrder[]
     */
    public function getWuliuOrders(): Collection
    {
        return $this->wuliuOrders;
    }

    public function addWuliuOrder(WuliuOrder $wuliuOrder): self
    {
        if (!$this->wuliuOrders->contains($wuliuOrder)) {
            $this->wuliuOrders[] = $wuliuOrder;
            $wuliuOrder->setGoods($this);
        }

        return $this;
    }

    public function removeWuliuOrder(WuliuOrder $wuliuOrder): self
    {
        if ($this->wuliuOrders->contains($wuliuOrder)) {
            $this->wuliuOrders->removeElement($wuliuOrder);
            // set the owning side to null (unless already changed)
            if ($wuliuOrder->getGoods() === $this) {
                $wuliuOrder->setGoods(null);
            }
        }

        return $this;
    }
}
